package wangyi;

public class Main2 {

    public static void main(String[] args) {
        Main2 main2 = new Main2();
        System.out.println(main2.findKthBit(3, 1));
    }

    public char findKthBit (int n, int k) {
        // write code here
        String[] ss = new String[n];
        ss[0] = "a";
        String[] ls = new String[26];
        for (int i = 0; i < 26; i++){
            ls[i] = String.valueOf((char)('a' + i));
        }
        for (int i = 1; i < n; i++){
            ss[i] = ss[i - 1] + ls[i] + reverse(invert(ss[i - 1]));
        }
        return ss[n - 1].charAt(k - 1);
    }

    public String reverse(String s){
        StringBuilder sb = new StringBuilder(s);
        return sb.reverse().toString();
    }

    public String invert(String s){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++){
            sb.append((char)((25 - (s.charAt(i) - 'a')) + 'a'));
        }
        return sb.toString();
    }
}
